﻿//===================================================================================
// $$
//
//
// Code By: Code Milker V2
// Date On: 2013//
//===================================================================================


namespace Forest.Lion.Data.SqlServer.Repositories
{
    using System;

    using System.Collections.Generic;

    using System.Data;

    using System.Linq;
    using Forest.Lion.Model;

    public class CertificationRepository : BaseRepository, ICertificationRepository
    {
        public CertificationRepository(IUnitOfWork unitOfWork)
            : base(unitOfWork)
        {
        }
        public void Create(Certification certification)
        {
            this.GetDbSet<Certification>().Add(certification);
            this.UnitOfWork.SaveChanges();
        }

        public Certification GetCertification(Guid certificationId)
        {
            return this.GetDbSet<Certification>()
                .Where(c => c.Id == certificationId)
                .Single();
        }

        public void Update(Certification updatedCertification)
        {
            this.GetDbSet<Certification>().Attach(updatedCertification);
            this.SetEntityState(updatedCertification, updatedCertification.Id == Guid.Empty
                ? EntityState.Added
                : EntityState.Modified);
            this.UnitOfWork.SaveChanges();
        }

        public void Delete(Guid certificationId)
        {
            Certification certificationToDelete = this.GetCertification(certificationId);
            this.GetDbSet<Certification>().Remove(certificationToDelete);
            this.UnitOfWork.SaveChanges();
        }

        public IEnumerable<Certification> Find()
        {
            return this.GetDbSet<Certification>().Take(100)
                .ToList();
        }

        public IEnumerable<Certification> GetAll()
        {
            return this.GetDbSet<Certification>().Take(100)
                .ToList();
        }
    }
}
